<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //集合实践
        let arr = [1, 4, 5, 3, 6, 2, 5, 3]

        //集合去重
        //可以通过扩展运算符转换为数组
        // let result = [...new Set(arr)];
        // console.log(result);  //[1,4,5,3,6,2]

        //取交集
        let arr2 = [4, 4, 5, 6, 7, 8, 7, 3]
        //先去重，然后取交集
        // let result = [...new Set(arr)].filter(item => {
        //     let s2 = new Set(arr2)
        //     if (s2.has(item)) {
        //         return true;
        //     } else {
        //         return false;
        //     }
        // })
        // console.log(result); //4,5,3,6

        //上面的代码简化
        // let result = [...new Set(arr)].filter(item =>new Set(arr2).has(item))
        // console.log(result);


        //取并集
    //    let unio = [...new Set([...arr,...arr2])];
    //    console.log(unio); //1,4,5,3,6,2,7,8



    //取差集
    //分清谁是主体
     let result = [...new Set(arr)].filter(item =>!(new Set(arr2).has(item)))
     console.log(result);

    </script>
</body>

</html>